//
//  CZFeatherViewController.m
//  CZOC微博01
//
//  Created by 1 on 15/11/29.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "CZFeatherViewController.h"
#import "CZTabbarController.h"
@interface CZFeatherViewController ()<UIScrollViewDelegate>
@property (nonatomic,weak) UIPageControl *control;
@end

@implementation CZFeatherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIScrollView *scrollView=[[UIScrollView alloc]init];
    scrollView.delegate=self;
    scrollView.frame=self.view.frame;
    [self.view addSubview:scrollView];
    CGFloat imageH=self.view.frame.size.height;
    CGFloat imageW=self.view.frame.size.width;
     //添加一个滚动的imageView
    for (int i=0; i<4; i++) {
        UIImageView *imageView=[[UIImageView alloc] init];
        
        NSString *imageName=[NSString stringWithFormat:@"new_feature_%d",i+1];
        
        
        imageView.image=[UIImage imageNamed:imageName];
        imageView.height=imageH;
        imageView.width=imageW;
        imageView.x=imageW*i;
        imageView.y=0;
        [scrollView addSubview:imageView];
        
         if(i==3)
         {
//             UIImageView *checkBox=[[UIImageView alloc] init];
//             UIButton *checkBox=[[UIButton alloc]init];
             //添加一个checkBox和登陆的按钮
             [self  addCheckAndLogin:imageView];
             
         }
        
        
    }
    
    scrollView.contentSize=CGSizeMake(imageW*4, 0);
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.showsVerticalScrollIndicator=NO;
    scrollView.pagingEnabled=YES;
    scrollView.bounces=NO;
    
    UIPageControl *page=[[UIPageControl alloc]init];
//    page.numberOfPages=4;
//    page.currentPage=0;
//    page.frame=CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)
//    page.center=self.view.center;
//    
//    page.bounds=CGRectMake(0, 0, 50, 20);
//    page.pageIndicatorTintColor=[UIColor redColor];
    
    page.translatesAutoresizingMaskIntoConstraints=NO;
    self.view.translatesAutoresizingMaskIntoConstraints=NO;
    NSLayoutConstraint *constantX=[NSLayoutConstraint constraintWithItem:page attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    NSLayoutConstraint *contsantY=[NSLayoutConstraint constraintWithItem:page attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:300];
    [self.view addConstraints:@[constantX,contsantY]];
//    [self.view addConstraint:contsantY];
//    [self.view addConstraint:constantX];
//    [self.view addConstraint(NSLayoutConstraint)];
    page.pageIndicatorTintColor=[UIColor redColor];
    page.numberOfPages=4;
    page.currentPage=0;
    page.currentPageIndicatorTintColor=[UIColor grayColor];
    [self.view addSubview:page];
//    page.size=CGSizeMake(300, 10);
//    page.width=0;
//    page.height=0;
    page.userInteractionEnabled=NO;
//    page.frame=CGRectZero;
//    page.backgroundColor=[UIColor redColor];
    self.control=page;
    
}
- (void)addCheckAndLogin:(UIImageView *)imageview
{
    UIButton *checkBox=[[UIButton alloc]init];
    [imageview addSubview:checkBox];
    checkBox.height=30;
    checkBox.width=120;
    checkBox.centerX=self.view.centerX;
    checkBox.y=self.view.height*0.7;
//    checkBox.frame=CGRectMake(0, 0, 50, 50);
    [checkBox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [checkBox setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [checkBox setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    [checkBox setTitle:@"分享功能" forState:UIControlStateNormal];
//    checkBox.backgroundColor=[UIColor redColor];
    [checkBox addTarget:self action:@selector(shareBtn:) forControlEvents:UIControlEventTouchUpInside];
    imageview.userInteractionEnabled=YES;
    checkBox.titleEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0);
    
    
    //添加一个按钮
    UIButton *startBtn=[[UIButton alloc]init];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
//    startBtn.size=startBtn.currentBackgroundImage.size;
    startBtn.width=150;
    startBtn.height=40;
    startBtn.centerX=checkBox.centerX;
    startBtn.centerY=imageview.height*0.8;
    [startBtn setTitle:@"开始体验 " forState:UIControlStateNormal];
    [imageview addSubview:startBtn];
    
    [startBtn addTarget:self action:@selector(startMain) forControlEvents:UIControlEventTouchUpInside];
    
    
}
- (void)startMain
{
    CZTabbarController *tabBarView=[[CZTabbarController alloc]init];
    
    [UIApplication sharedApplication].keyWindow.rootViewController=tabBarView;
  
}
- (void)shareBtn:(UIButton *)btn
{
    btn.selected=!btn.selected;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offX=scrollView.contentOffset.x;
    
    NSInteger index=(offX+self.view.frame.size.width*0.5)/self.view.frame.size.width;
    
    self.control.currentPage=index;
    
    
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
